﻿#ifndef TEXT_H
#define TEXT_H

/*
 * 在该头文件中,我依次将SECS-II标准中
 * ASCII,Binary,Boolean,F4,F8,U1~U8,I1~I8,LIST
 * 这几种数据类型的MessageText-->QByteArray的过程进行了实现
 * 其中,LIST类型的数据结构需要格外注意!
 */
#include "src/enum/secsenum.h"
#include "src/util/conversionutil.h"

#include <QObject>

class Text : public QObject
{
    Q_OBJECT
public:
    /*
     * 对于非LIST类型数据,该函数返回的是"数据个数*sizeof(数据)"
     * 对于LIST类型数据,该函数返回的是子元素个数
     */
    virtual int getLength() = 0;

    /*
     * 依据数据载荷,将MessageText的内容进行组装
     * 这是一个Message-->QByteArray的过程
     * 最终目的是要在ParseUtil中针对DataMessage完成byte数组的组装
     */
    virtual QByteArray getByteArray() = 0;

    /*
     * 将数据载荷以<...>的形式进行输出,便于后续数据的展示
     */
    virtual QString getString(int level) = 0;
};


class TextASCII : public Text
{
public:
    TextASCII();
    TextASCII(QString value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextASCIIPrivate;
    std::shared_ptr<TextASCIIPrivate> d;
};


class TextBinary : public Text
{
public:
    TextBinary(){}
    TextBinary(std::vector<char> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextBinaryPrivate;
    std::shared_ptr<TextBinaryPrivate> d;
};


class TextBoolean : public Text
{
public:
    TextBoolean();
    TextBoolean(bool value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextBooleanPrivate;
    std::shared_ptr<TextBooleanPrivate> d;
};


class TextF4 : public Text
{
public:
    TextF4();
    TextF4(std::vector<float> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextF4Private;
    std::shared_ptr<TextF4Private> d;
};


class TextF8 : public Text
{
public:
    TextF8();
    TextF8(std::vector<double> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextF8Private;
    std::shared_ptr<TextF8Private> d;
};


class TextI1 : public Text
{
public:
    TextI1();
    TextI1(std::vector<qint8> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextI1Private;
    std::shared_ptr<TextI1Private> d;
};


class TextI2 : public Text
{
public:
    TextI2();
    TextI2(std::vector<qint16> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextI2Private;
    std::shared_ptr<TextI2Private> d;
};


class TextI4 : public Text
{
public:
    TextI4();
    TextI4(std::vector<qint32> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextI4Private;
    std::shared_ptr<TextI4Private> d;
};


class TextI8 : public Text
{
public:
    TextI8();
    TextI8(std::vector<qint64> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextI8Private;
    std::shared_ptr<TextI8Private> d;
};


class TextU1 : public Text
{
public:
    TextU1();
    TextU1(std::vector<quint8> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextU1Private;
    std::shared_ptr<TextU1Private> d;
};


class TextU2 : public Text
{
public:
    TextU2();
    TextU2(std::vector<quint16> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextU2Private;
    std::shared_ptr<TextU2Private> d;
};


class TextU4 : public Text
{
public:
    TextU4();
    TextU4(std::vector<quint32> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextU4Private;
    std::shared_ptr<TextU4Private> d;
};


class TextU8 : public Text
{
public:
    TextU8();
    TextU8(std::vector<quint64> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

private:
    friend struct TextU8Private;
    std::shared_ptr<TextU8Private> d;
};


class TextList : public Text
{
public:
    TextList();
    TextList(std::vector<Text*> value);
    int getLength() override;
    QByteArray getByteArray() override;
    QString getString(int level) override;

    Text* getItem(int index);
    void addItem(Text* item);

private:
    friend struct TextListPrivate;
    std::shared_ptr<TextListPrivate> d;
};

#endif // TEXT_H
